package cn.hinglo.gameclaw.admin.action;

import cn.hinglo.gameclaw.admin.service.ClawImageService;
import cn.hinglo.gameclaw.data.controller.BaseController;
import cn.hinglo.gameclaw.data.entity.Result;
import cn.hinglo.gameclaw.user.bean.ClawImage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @createTime: 2018/1/2
 * @author: HingLo
 * @description: 娃娃机的详情图管理
 */
@RestController
@RequestMapping("admin/ci/")
public class ClawImageAction extends BaseController {

    private final ClawImageService clawImageService;

    @Autowired
    public ClawImageAction(ClawImageService clawImageService) {
        this.clawImageService = clawImageService;
    }


    /**
     * 查询娃娃机的详情图
     *
     * @param cid 娃娃机详情图的唯一Id
     * @return 详情图列表
     */
    @GetMapping("list")
    public Result listClawImage(@RequestParam("cid") int cid) {
        return success(clawImageService.listClawImageService(cid));
    }


    /**
     * 删除娃娃机的详情图片
     *
     * @param id 娃娃机详情的唯一Id
     * @return 操作结果
     */
    @DeleteMapping("delete")
    public Result deleteClawImage(String id) {
        return clawImageService.deleteClawImageService(id);
    }

    /**
     * 添加娃娃机的详情图
     *
     * @param clawImage     娃娃机详情图对象
     * @param header        图片
     * @param bindingResult 错误绑定对象
     * @return 操作结果
     */
    @PostMapping("add")
    public Result addClawImage(ClawImage clawImage, BindingResult bindingResult, @RequestParam("header") MultipartFile header) {
        if (bindingResult.hasErrors()) {
            return error(bindingResult.getFieldError().getDefaultMessage());
        }
        return clawImageService.addClawImageService(clawImage, header);
    }


}
